// pages/firstpage/zanzhu1/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isHasFujian:'点击上传照片',
    img_l:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  editClick(){
    let self = this;
    let url = `${ApiRootUrl}/people/checkFloatPeople`;
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: url,
      method: 'GET',
      header: {
        'content-type': 'application/json; charset=utf-8',
        'cookie': wx.getStorageSync("sessionid")
      },
      success(res){
        wx.hideLoading()
       
        if (res.data.code == 20000) {
          console.log("res====>",res)
          if(res.data.data.b==true&&res.data.data.c==true){
            console.log(res.data.data);
          }else{
            Toast({
              duration: 3000,
              forbidClick: true,
              type: 'fail',
              message:'您暂不需要更新信息',
              mask:true
            });
            setTimeout(()=>{
              wx.navigateBack()
            },3000)
          }
        } else {
          Toast({
            duration: 3000,
            forbidClick: true,
            type: 'fail',
            message: res.data.message,
            mask:true
          });
        }
      },
      fail(res) {
        wx.hideLoading()
        Toast({
          duration: 3000,
          forbidClick: true,
          type: 'fail',
          message: '网络已断开',
        });
      }
    })
 
  },
  upLoadImg(){
    let self = this;
    wx.chooseImage({
      count: 1,
      success(res){
        console.log('上传文件',res);
        self.setData({
          img_l: res.tempFilePaths
        })
        Toast.loading({
          duration: 0,
          message: '加载中...',
          forbidClick: true,
        });
        // console.log(res.tempFilePaths[0].replace("http:","https:"));
        wx.uploadFile({
          url: ApiRootUrl + '/people/uploadPhoto', 
          filePath: res.tempFilePaths[0],
          name: 'file',
          formData:{
            // openId:wx.getStorageSync('openId'),
            // oldPath:self.data.oldPath || ''
          },
          header: {
            "Content-Type": "multipart/form-data",
            'cookie': wx.getStorageSync("sessionid")
          },
          success(res) {
            Toast.clear();
            Toast.success('照片上传成功!');
            self.setData({
              isHasFujian:'已上传'
            })
          },
          fail(res) {
            Toast.clear();
            console.log(res)
            // Toast.fail(JSON.stringify(res));
            Toast({
              duration: 0,
              // forbidClick: true,
              type: 'fail',
              message: JSON.stringify(res),
              mask:'true'
            });
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})